package com.dcivision.framework.taglib.channel.event;

import java.sql.Connection;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.dcivision.alert.AlertOperationConstant;
import com.dcivision.alert.bean.UpdateAlertLogAction;
import com.dcivision.alert.bean.UpdateAlertSystemLog;
import com.dcivision.alert.core.AlertManager;
import com.dcivision.framework.ApplicationException;
import com.dcivision.framework.SessionContainer;

public class SystemLogs extends AbstractAjaxAction{
  
  private static final Log log = LogFactory.getLog(SystemLogs.class);
  
  public  void updateReadOperationLog(String[] args) throws ApplicationException{
    Connection conn = this.getConnection();
    SessionContainer sessionContainer = this.getSessionContainer();
    //ListPersonalHomeForm listForm = (ListPersonalHomeForm) args[0];
    //Integer systemLogID = listForm.getActionSystemLogID();
    Integer systemLogID = Integer.valueOf(args[0]);
    if (systemLogID!=null) {
      AlertManager alertManager = new AlertManager(sessionContainer, conn);
      //log.debug("OpMode:"+listForm.getOpMode());
      if (AlertOperationConstant.UNREAD_OPERATION.equals(args[1]) &&
        alertManager.checkForSystemLogActionByActionType(systemLogID, UpdateAlertLogAction.READ_ACTION)) {
        alertManager.deleteLogActionBySystemLogIDCurActor(systemLogID);
      }
      else if(AlertOperationConstant.READ_OPERATION.equals(args[1])){
        //Go create read record
        UpdateAlertSystemLog systemLog = new UpdateAlertSystemLog();
        systemLog.setID(systemLogID);
        alertManager.createSystemLogAction(systemLog, UpdateAlertLogAction.READ_ACTION, null, null);
      }
    }
    //listForm.setOpMode(null);
    //listForm.setActionSystemLogID(null);
    try{}catch(Exception e){log.error(e, e);}finally{ conn=null;}
  }
  
  public  void updateReadActionOperationLog(String[] args) throws ApplicationException{
    Connection conn = this.getConnection();
    SessionContainer sessionContainer = this.getSessionContainer();
    Integer systemLogID;
    for(int i=0;i<args.length;i++){
    systemLogID = Integer.valueOf(args[i]);
    if (systemLogID!=null) {
      AlertManager alertManager = new AlertManager(sessionContainer, conn);
        UpdateAlertSystemLog systemLog = new UpdateAlertSystemLog();
        systemLog.setID(systemLogID);
        alertManager.createSystemLogAction(systemLog, UpdateAlertLogAction.READ_ACTION, null, null);
    }
    }
    try{}catch(Exception e){log.error(e, e);}finally{ conn=null;}
  }

  public String acceptMeetingInvication(String[] args)throws ApplicationException{
    
    return null;
  }
  
  public Object execute() throws ApplicationException {
    
    return null;
  }
}
